<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // 展开数组
        let a = [1, 2, 3, 4, 5]
        console.log(...a); //=> 1 2 3 4 5

        // 合并两个数组
        let b = [6, 7, 8, 9]
        console.log([...a, ...b]); //=> [1, 2, 3, 4, 5, 6, 7, 8, 9]

        // 方法接收不定数参数
        function sum(...numbers) {
            // 接收到的是一个数组
            console.log(numbers);
            return numbers.reduce((a, b) => {
                return a + b
            }, 0)
        }
        console.log(sum(1, 2, 3)); //=> 6
        console.log(sum(3)); //=> 3

        // 使用展开语法浅拷贝对象,这种方法只能复制对象中第一层的数据
        let person = {
            name: "Tom",
            age: 19,
            classInfo: {
                height: 180
            }
        }
        let person2 = {
            ...person
        }
        person.name = "jery"
        person.classInfo.height = 190

        console.log(person2); //=> {"name":"Tom","age":19,"classInfo":{"height":190}}
        console.log(person); //=> {"name":"jery","age":19,"classInfo":{"height":190}}

    </script>
</body>

</html>